//
// Created by F1997 on 2024/12/24.
//

#ifndef NETWORK_TRAFFIC_PROCESSING_V2_PCAPUTILS_H
#define NETWORK_TRAFFIC_PROCESSING_V2_PCAPUTILS_H
#include "pch.h"
#include "IniReader.h"
#include "headers.hpp"
#include "SafeQueueTemplate.h"
#include "CompareTraffic.h"
#include "SPMCQueueTemplate.h"
#include "ThreadPoolV2.hpp"
#include "../decode/zce_decode.h"
#include "../decode/shfe_decode.h"
#include "../decode/dce_decode.h"


namespace ntp {

    // pcap抓包工具类
    class PcapUtils {
    public:
        PcapUtils() = default;

        // 列表初始化和优化，{}还是()???
        PcapUtils(std::shared_ptr<spdlog::logger> _my_logger, ShareDataClzz* _shareDataClzz) //, IniReader* _iniCfg, CompareTraffic _compareTraffic)
        //: my_logger(_my_logger), iniCfg(_iniCfg)
        //compareTraffic(_compareTraffic)
        {
            my_logger = _my_logger;
            //shareDataClzz = _shareDataClzz;
            //iniCfg = _iniCfg;
            //compareTraffic = new CompareTraffic(iniCfg);
            p_t = new ThreadPool(2);

        };

        void readPcapFile();

        bool checkIsStart(std::chrono::system_clock::time_point startTime, int offset);

        int readNetworkIfaceLine(std::string sectionId, std::chrono::system_clock::time_point startTime, IniReader* iniCfg, SafeQueue<MarketData>* data_queue, std::string debug);
        int readNetwork(std::string sectionId, std::chrono::system_clock::time_point startTime, IniReader* iniCfg);


        int readMsg(std::shared_ptr<spdlog::logger> my_logger, IniReader* iniCfg, SafeQueue<MarketData>* data_queue1, SafeQueue<MarketData>* data_queue2, std::string debug);
        int saveFile(std::shared_ptr<spdlog::logger> _my_logger, IniReader* iniCfg);

        std::chrono::system_clock::time_point parseTime(const std::string& timeStr);
        std::chrono::system_clock::time_point string_to_time_point(const std::string& str);
        time_t parse_date_to_timestamp(const std::string& date_str);

    private:
        //ShareDataClzz* shareDataClzz;
        // 流量对比类
        std::shared_ptr<spdlog::logger> my_logger;
        //CompareTraffic compareTraffic;
        CompareTraffic compareTraffic;
        ThreadPool* p_t;
        int g_exit = 0;

    };


} // ntp

#endif //NETWORK_TRAFFIC_PROCESSING_V2_PCAPUTILS_H
